New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add index on stream_entries table #5793
add index on stream_entries table #5793
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this sped up timeline queries significantly on my instance
f063861
to
d00e15d
Compare
Isn't a query like this used only on the Atom feed and only when you're paginating it? How could this have improved timelines @kaniini? |
Sorry, I meant when loading some specific account's timeline. |
class AddIndexOnStreamEntries < ActiveRecord::Migration[5.1] | ||
def change | ||
commit_db_transaction | ||
add_index :stream_entries, [:id, :account_id, :activity_type], algorithm: :concurrently |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you should put id
at the last for sorting. By putting account_id
at the very beginning you can also cover index_stream_entries_on_account_id
and remove it.
Requesting a review from @abcang; he has suggested a similar change for Pawoo, but it is also concerning the idea I suggested in #5793 (review). |
I still don't think this could have any effect on that? As far as I remember account timelines use |
I also recognized that stream_entries is currently used only for atom feed. However, instances that do not correspond to ActivityPub are accessing atom feed, so I think that it will be effective for instances connected to such instances. Also, I think that it is more effective for instances that have many stream_entries like Pawoo. |
f063861
to
b6355bb
Compare
Thank you for review.
|
This statement was executed 45974 times in the last 6 days at imastodon.net. I think this is still necessary. |
add index on stream_entries table (mastodon#5793)
This pull request is adding index for below statement .
SELECT "stream_entries".* FROM "stream_entries" WHERE "stream_entries"."activity_type" = ? AND "stream_entries"."account_id" = ? AND "stream_entries"."hidden" = ? ORDER BY "stream_entries"."id" DESC LIMIT ?
This statement executed 67,112 times.
before
after